<template>
	<view>
		<IndexCard ref="IndexCardRef" :isBackHome="isBackHome" @createCard="createCard" :showM='showM' :isOther="1" />
		<!-- 过期 -->
		<view class="mask" v-if="false">
			<view class="mask-popup">
				<view class="mask-popup-title">TA的会员已到期</view>
				<view class="mask-popup-btn">
					<view class="mask-popup-btn-l">他的其他名片</view>
					<view class="mask-popup-btn-r" @click="toMyPage">返回我的主页</view>
				</view>
			</view>
		</view>
	</view>
</template>

<script>
	import IndexCard from './indexCard.vue'
	import {
		userShareRecord,
		InformationBusinessCardList,
		user_circle_type
	} from '@/common/http/api.js'
	export default {
		components: {
			IndexCard
		},
		data() {
			return {
				showM: false,
				userId: '',
				shareId: '',
				isBackHome: 1,
				isCreateCard: 0, //0 没得名片 1 有名片
				token: ''
			};
		},
		async onLoad(e) {

			if (e.userId) {
				this.userId = e.userId
			}
			if (e.shareId) {
				this.shareId = e.shareId
			}
			//是否返回首页
			if (e.isBackHome) {
				this.isBackHome = e.isBackHome
			}

			let token = uni.getStorageSync('token')
			if (!token) {
				this.login()
			} else {
				this.$refs.IndexCardRef.getData({
					userId: this.userId,
					shareId: this.shareId,
					otherType: 2 //1首页 2其他
				})
			}

		},
		onShow() {
			this.showM = false
			this.$nextTick(() => {
				this.showM = true
			})
		},
		onShareAppMessage() {
			let img = ''
			let title = ''
			let path = '/pages/loading/loading'
			if (this.$store.state.cardInfo.Friend_Status != 1) {
				path += '?shareId=' + this.$store.state.share.business_card_id
				img = this.ossUrl + '/static/share.jpg'
				return {
					title: `这是 ${this.$store.state.cardInfo.nickname} 的电子名片`,
					path,
					imageUrl: img
				};
			}
			if (this.isValid(this.$store.state.share.share_title)) {

				title = this.$store.state.share.share_title
				img = this.$store.state.share.intercept ? this.$store.state.share.intercept : this.$store.state.share
					.share_img
				path += '?shareId=' + this.$store.state.share.business_card_id

				//计算人数
				let token = uni.getStorageSync('token')
				if (token) {
					let data = {
						my: this.$store.state.userInfo.id,
						you: this.$store.state.share.user_id,
						business_card_id: this.$store.state.share.business_card_id
					}
					userShareRecord(data)
				}

			}

			console.log('分享的', this.$store.state.share)
			console.log('分享的', title, path, img)
			return {
				title,
				path,
				imageUrl: img
			};
		},
		//收藏
		onAddToFavorites(res) {
			console.log('收藏mixin', this.$store.state)
			let img = ''
			let title = ''
			let path = 'is_mixin_collect=1&'
			if (this.$store.state.cardInfo.Friend_Status != 1) {
				path += 'shareId=' + this.$store.state.share.business_card_id
				img = this.ossUrl + '/static/share.jpg'
				return {
					title: `这是 ${this.$store.state.cardInfo.nickname} 的电子名片`,
					query: path,
					imageUrl: img
				};
			}
			if (this.isValid(this.$store.state.share.share_title)) {
				title = this.$store.state.share.share_title
				img = this.$store.state.share.intercept ? this.$store.state.share.intercept : this.$store.state.share
					.share_img
				path += 'shareId=' + this.$store.state.share.business_card_id
				// if (this.$store.state.userInfo.id) {
				// 	path += '?shareId=' + this.$store.state.share.business_card_id + '&userId=' + this.$store.state
				// 		.userInfo.id
				// } else {
				// 	path += '?shareId=' + this.$store.state.share.business_card_id
				// }
				let token = uni.getStorageSync('token')
				if (token) {
					let data = {
						my: this.$store.state.userInfo.id,
						you: this.$store.state.share.user_id,
						business_card_id: this.$store.state.share.business_card_id
					}
					userShareRecord(data)
				}

			}
			return {
				title,
				query: path,
				imageUrl: img
			};
		},
		// onHide() {
		// 	this.setShare()
		// },
		methods: {
			toMyPage() {
				uni.switchTab({
					url: '/pages/index/index'
				})
			},
			login() {
				this.$store.dispatch('login', {
					userId: this.userId,
					shareId: this.shareId
				}).then(() => {
					this.$refs.IndexCardRef.getData({
						userId: this.userId,
						shareId: this.shareId,
						otherType: 2 //1首页 2其他
					})
				}).catch(() => {
					this.$u.toast('登录失败！')
					setTimeout(() => {
						this.login()
					}, 1500)

				})

			},
			createCard(e) {

				if (this.token) {
					if (e > 0) {
						uni.navigateTo({
							url: '/pages/index/addMyCard?circle_id=' + e
						})
					} else {
						uni.navigateTo({
							url: '/pages/index/addMyCard'
						})
					}

				} else {
					let params = `?a=1`
					if (this.userId) {
						params += `&userId=${this.userId}`
					}
					if (this.shareId) {
						params += `&shareId=${this.shareId}`
					}
					uni.navigateTo({
						url: '/pages/login/login' + params
					})
				}
			}
		}
	}
</script>

<style lang="scss" scoped>
	.mask {
		width: 100vw;
		height: 100vh;
		position: fixed;
		top: 0;
		left: 0;
		z-index: 99999;
		background-color: rgba(255, 255, 255, 0.4);
		/* 半透明背景 */
		backdrop-filter: blur(15rpx);
		/* 高斯模糊程度 */
		-webkit-backdrop-filter: blur(15rpx);
		/* 兼容 Safari 浏览器 */
		display: flex;
		justify-content: center;
		align-items: center;

		.mask-popup {
			border-radius: 50rpx;
			background: rgba(0, 0, 0, 0.6);
			width: 500rpx;

			.mask-popup-title {
				font-size: 26rpx;
				width: 100%;
				padding: 30rpx 30rpx 10rpx;
				box-sizing: border-box;
				color: #fff;
				text-align: center;

			}

			.mask-popup-btn {
				width: 100%;
				display: flex;
				padding: 30rpx 0;

				.mask-popup-btn-l::after {
					content: "";
					width: 1rpx;
					height: 80%;
					position: absolute;
					right: 0;
					top: 50%;
					transform: translateY(-50%);
					background: white;
				}

				view {
					font-size: 26rpx;
					color: #fff;
					flex: 1;
					position: relative;
					text-align: center;
				}
			}
		}
	}
</style>